hii,
can you tell me plzz why my programme doesn`t work ,i don`t have any
errors and every thing is fine but i don`t know why it`s not working ,
soo plz can you help me un finding my mistake
i will past the proramme here ,
the headers,
#include<string >
using namespace std;
#ifndef H_Gymnasium
#define H_Gymnasium
struct activities
{
string exercises;
int time;
};
class Gymnasium
{
protected:
activities gymarray[5];
int gymlength;
public:
void set(string,int) ;
void getActivities(s tring&,int&)con st;
double calories();
void print();
Gymnasium(strin g="", int=0 );
};
#endif
#include<string >
using namespace std;
#ifndef H_Nutrition
#define H_Nutrition
struct meals
{
string food;
int portion;
};
class Nutrition
{
protected:
meals nutritionarray[5];
int nutritionLength ;
public:
void set(string,int) ;
void getMeals(string & , int&)const;
void print();
Nutrition(strin g="" , int=0);
double calories();
};
#endif
#include <string>
#include"Regime .h"
#ifndef H_Patient
#define H_Patient
using namespace std;
struct person
{
string name;
double energy;
};
class Patient:public Gymnasium , public Nutrition,publi c Regime
{
public:
void set(string,int, string,int,stri ng,double);
void get(string&,int & ,string& ,int&,string&,d ouble&)const;
void print();
Patient(string= "",int=0,string ="",int=0,strin g=0,double=0);
double calories(); // find the difference between gained & lost
calories and
//and sub. it from the energy
private:
person info;
Regime regimePlan;
};
#endif
#include<string >
#include"Gymnas ium.h"
#include"Nutrit ion.h"
#ifndef H_Regime
#define H_Regime
using namespace std;
class Regime
{
public:
void set(string,int ,string,int);
void print();
Regime(string=" " ,int=0,string=" ",int=0);
double calories();
private:
Gymnasium exercisePlan ;
Nutrition dietPlan;
};
#endif
=============== =============== =============== ==
the implitation
#include <iostream>
#include <string>
#include "Gymnasium. h"
using namespace std;
const int gymlength=5;
void Gymnasium::set( string ex , int T )
{
gymarray[gymlength].exercises=ex;
gymarray[gymlength].time=T;
}
void Gymnasium::getA ctivities(strin g& ex , int& T )const
{
ex=gymarray[gymlength].exercises;
T=gymarray[gymlength].time;
}
void Gymnasium::prin t()
{
cout<<"He/She lost "<<calories()<< "calories"<<end l;
}
Gymnasium::Gymn asium(string ex , int T )
{
gymarray[gymlength].exercises=ex;
gymarray[gymlength].time=T;
}
double Gymnasium:: calories()
{
int total,calories ,i,lostcalories ;
for(i=0;i>gymle ngth;i++)
{
if (gymarray[i].exercises=="Op enGym"){
calories=680*gy marray[i].time;
}
else if (gymarray[i].exercises=="Tr eadmill"){
calories=820*gy marray[i].time;
}
else if (gymarray[i].exercises=="Bi ke"){
calories=620*gy marray[i].time;
}
else if (gymarray[i].exercises=="Fi tness"){
calories=740*gy marray[i].time;
}
else if (gymarray[i].exercises=="Ho op"){
calories=210*gy marray[i].time;
}
total+=calories ;
}
lostcalories=to tal/60;
return lostcalories;
}
#include<iostre am>
#include<string >
#include"Nutrit ion.h"
using namespace std;
const int Nutritionlength =4;
void Nutrition::set( string f , int p )
{
nutritionarray[Nutritionlength].food=f;
nutritionarray[Nutritionlength].portion=p;
}
void Nutrition ::getMeals(stri ng&f , int&p )const
{
f=nutritionarra y[Nutritionlength].food;
p=nutritionarra y[Nutritionlength].portion;
}
Nutrition::Nutr ition(string f , int p )
{
set(f,p);
}
double Nutrition::calo ries()
{
int total,calories ,i,gainedcalori es;
for(i=0;i>4;i++ )
{
nutritionarray[i].food;
nutritionarray[i].portion;
if (nutritionarray[i].food=="Carbohy drates"){
calories=90*nut ritionarray[i].portion;
}
else if (nutritionarray[i].food=="Protein "){
calories=70*nut ritionarray[i].portion;
}
else if (nutritionarray[i].food=="Vitamin s"){
calories=50*nut ritionarray[i].portion;
}
else if (nutritionarray[i].food=="Water") {
calories=10*nut ritionarray[i].portion;
}
total+=calories ;
}
gainedcalories= total/100;
return gainedcalories;
}
void Nutrition:: print()
{
cout<<"He/She gained "<<calories()<< "calories"<<end l;
}
#include<iostre am>
#include <string>
#include"Patien t.h"
using namespace std;
void Patient::set(st ring ex,int T,string f,int p,string n,double e)
{
Gymnasium::set( ex,T);
Nutrition::set( f,p);
info.name=n;
info.energy=e;
}
void Patient::get(st ring& ex,int& T ,string& f ,int& p,string&
n,double&e)cons t
{
Gymnasium::getA ctivities(ex,T) ;
Nutrition::getM eals(f,p);
n=info.name;
e=info.energy;
}
void Patient::print( )
{
cout<<"Before the regime"<<info.n ame<<"energy was
"<<calories()<< "calories"<<end l;
Regime::print() ;
Gymnasium::prin t();
Nutrition::prin t();
}
Patient::Patien t(string ex,int T,string f,int p,string n,double
e):Gymnasium(ex ,T),Nutrition(f ,p),
Regime(ex,T,f,p )
{
n=info.name;
e=info.energy;
}
double Patient::calori es()
{
int before;
before=Regime:: calories()+600;
return before;
}
#include<iostre am>
#include<string >
#include"Regime .h"
using namespace std;
void Regime::set(str ing ex,int T,string f,int p)
{
exercisePlan.se t(ex,T);
dietPlan.set(f, p);
}
void Regime::print()
{
cout<<"After the regime Ahmed energy is
"<<calories()<< "calories"<<end l;
}
Regime::Regime( string ex,int T,string f,int p)
{
exercisePlan.se t(ex,T);
dietPlan.set(f, p);
}
double Regime::calorie s()
{
int After;
After=dietPlan. calories()- exercisePlan.ca lories();
return After;
}
=============== =============== ==
the driver
#include<iostre am>
#include<string >
#include<fstrea m>
#include"Gymnas ium.h"
#include"Nutrit ion.h"
#include"Patien t.h"
#include"Regime .h"
using namespace std;
int main()
{
Patient A;
int T,p ;
string f , ex , n;
double e;
cin>>n>>e;
cout<<endl;
ifstream inFile;
inFile.open("pa tientActivities .txt");
inFile>>ex>>T;
inFile.close();
inFile.open("pa tientMeals.txt" );
inFile>>f>>p;
inFile.close();
A.set(ex,T,f,p, n,e);
A.print();
return 0;
}
can you tell me plzz why my programme doesn`t work ,i don`t have any
errors and every thing is fine but i don`t know why it`s not working ,
soo plz can you help me un finding my mistake
i will past the proramme here ,
the headers,
#include<string >
using namespace std;
#ifndef H_Gymnasium
#define H_Gymnasium
struct activities
{
string exercises;
int time;
};
class Gymnasium
{
protected:
activities gymarray[5];
int gymlength;
public:
void set(string,int) ;
void getActivities(s tring&,int&)con st;
double calories();
void print();
Gymnasium(strin g="", int=0 );
};
#endif
#include<string >
using namespace std;
#ifndef H_Nutrition
#define H_Nutrition
struct meals
{
string food;
int portion;
};
class Nutrition
{
protected:
meals nutritionarray[5];
int nutritionLength ;
public:
void set(string,int) ;
void getMeals(string & , int&)const;
void print();
Nutrition(strin g="" , int=0);
double calories();
};
#endif
#include <string>
#include"Regime .h"
#ifndef H_Patient
#define H_Patient
using namespace std;
struct person
{
string name;
double energy;
};
class Patient:public Gymnasium , public Nutrition,publi c Regime
{
public:
void set(string,int, string,int,stri ng,double);
void get(string&,int & ,string& ,int&,string&,d ouble&)const;
void print();
Patient(string= "",int=0,string ="",int=0,strin g=0,double=0);
double calories(); // find the difference between gained & lost
calories and
//and sub. it from the energy
private:
person info;
Regime regimePlan;
};
#endif
#include<string >
#include"Gymnas ium.h"
#include"Nutrit ion.h"
#ifndef H_Regime
#define H_Regime
using namespace std;
class Regime
{
public:
void set(string,int ,string,int);
void print();
Regime(string=" " ,int=0,string=" ",int=0);
double calories();
private:
Gymnasium exercisePlan ;
Nutrition dietPlan;
};
#endif
=============== =============== =============== ==
the implitation
#include <iostream>
#include <string>
#include "Gymnasium. h"
using namespace std;
const int gymlength=5;
void Gymnasium::set( string ex , int T )
{
gymarray[gymlength].exercises=ex;
gymarray[gymlength].time=T;
}
void Gymnasium::getA ctivities(strin g& ex , int& T )const
{
ex=gymarray[gymlength].exercises;
T=gymarray[gymlength].time;
}
void Gymnasium::prin t()
{
cout<<"He/She lost "<<calories()<< "calories"<<end l;
}
Gymnasium::Gymn asium(string ex , int T )
{
gymarray[gymlength].exercises=ex;
gymarray[gymlength].time=T;
}
double Gymnasium:: calories()
{
int total,calories ,i,lostcalories ;
for(i=0;i>gymle ngth;i++)
{
if (gymarray[i].exercises=="Op enGym"){
calories=680*gy marray[i].time;
}
else if (gymarray[i].exercises=="Tr eadmill"){
calories=820*gy marray[i].time;
}
else if (gymarray[i].exercises=="Bi ke"){
calories=620*gy marray[i].time;
}
else if (gymarray[i].exercises=="Fi tness"){
calories=740*gy marray[i].time;
}
else if (gymarray[i].exercises=="Ho op"){
calories=210*gy marray[i].time;
}
total+=calories ;
}
lostcalories=to tal/60;
return lostcalories;
}
#include<iostre am>
#include<string >
#include"Nutrit ion.h"
using namespace std;
const int Nutritionlength =4;
void Nutrition::set( string f , int p )
{
nutritionarray[Nutritionlength].food=f;
nutritionarray[Nutritionlength].portion=p;
}
void Nutrition ::getMeals(stri ng&f , int&p )const
{
f=nutritionarra y[Nutritionlength].food;
p=nutritionarra y[Nutritionlength].portion;
}
Nutrition::Nutr ition(string f , int p )
{
set(f,p);
}
double Nutrition::calo ries()
{
int total,calories ,i,gainedcalori es;
for(i=0;i>4;i++ )
{
nutritionarray[i].food;
nutritionarray[i].portion;
if (nutritionarray[i].food=="Carbohy drates"){
calories=90*nut ritionarray[i].portion;
}
else if (nutritionarray[i].food=="Protein "){
calories=70*nut ritionarray[i].portion;
}
else if (nutritionarray[i].food=="Vitamin s"){
calories=50*nut ritionarray[i].portion;
}
else if (nutritionarray[i].food=="Water") {
calories=10*nut ritionarray[i].portion;
}
total+=calories ;
}
gainedcalories= total/100;
return gainedcalories;
}
void Nutrition:: print()
{
cout<<"He/She gained "<<calories()<< "calories"<<end l;
}
#include<iostre am>
#include <string>
#include"Patien t.h"
using namespace std;
void Patient::set(st ring ex,int T,string f,int p,string n,double e)
{
Gymnasium::set( ex,T);
Nutrition::set( f,p);
info.name=n;
info.energy=e;
}
void Patient::get(st ring& ex,int& T ,string& f ,int& p,string&
n,double&e)cons t
{
Gymnasium::getA ctivities(ex,T) ;
Nutrition::getM eals(f,p);
n=info.name;
e=info.energy;
}
void Patient::print( )
{
cout<<"Before the regime"<<info.n ame<<"energy was
"<<calories()<< "calories"<<end l;
Regime::print() ;
Gymnasium::prin t();
Nutrition::prin t();
}
Patient::Patien t(string ex,int T,string f,int p,string n,double
e):Gymnasium(ex ,T),Nutrition(f ,p),
Regime(ex,T,f,p )
{
n=info.name;
e=info.energy;
}
double Patient::calori es()
{
int before;
before=Regime:: calories()+600;
return before;
}
#include<iostre am>
#include<string >
#include"Regime .h"
using namespace std;
void Regime::set(str ing ex,int T,string f,int p)
{
exercisePlan.se t(ex,T);
dietPlan.set(f, p);
}
void Regime::print()
{
cout<<"After the regime Ahmed energy is
"<<calories()<< "calories"<<end l;
}
Regime::Regime( string ex,int T,string f,int p)
{
exercisePlan.se t(ex,T);
dietPlan.set(f, p);
}
double Regime::calorie s()
{
int After;
After=dietPlan. calories()- exercisePlan.ca lories();
return After;
}
=============== =============== ==
the driver
#include<iostre am>
#include<string >
#include<fstrea m>
#include"Gymnas ium.h"
#include"Nutrit ion.h"
#include"Patien t.h"
#include"Regime .h"
using namespace std;
int main()
{
Patient A;
int T,p ;
string f , ex , n;
double e;
cin>>n>>e;
cout<<endl;
ifstream inFile;
inFile.open("pa tientActivities .txt");
inFile>>ex>>T;
inFile.close();
inFile.open("pa tientMeals.txt" );
inFile>>f>>p;
inFile.close();
A.set(ex,T,f,p, n,e);
A.print();
return 0;
}
Comment